import React, { useEffect } from 'react'
import { useSelector } from 'react-redux';
import { Text, View, Image, router } from '@ray-js/ray';
import styles from './index.module.less';
import { selectCustom } from '@/redux/modules/customSlice';
import { qing, duoyun, shaoyun, yintian, xiaoyu, dayu, baoyu, lzyu, lzybybb, dongyu, yujiaxue, xue, daxue, bingbao, bingli, bingzhen, leidian, leibao, wu, mai, scb, cjf, yangsha, fuc, rainfall } from '@/res';
import Strings from '@/i18n';
import { getWeek } from '@/utils';
type Porps = {
  plans?:any[]
}
export default function Weather( Porps ) {
  const { plans } = Porps
  const weathers: any[] = useSelector(selectCustom('weather'))
 
  function getWeekdayFromTimestamp(timestamp) {
    var date = new Date(timestamp);
    return getWeek(date.getDay());
  }
  //获取日志
  useEffect(() => {
    console.log("天气信息", weathers);
  }, [])
  const hasWork = (timestamp) => {
    // console.log("plans :",plans);
    var date = new Date(timestamp);  
     var  mon =('0' + (date.getMonth() + 1)).slice(-2)
     var  day =('0' + (date.getDate())).slice(-2)
       if(!plans){
         return (<></>)
       }
      var result = plans.find( element => {
        // console.log("plans find:",element.date,(mon+"-"+day));
       return (element.date == (mon+"-"+day))
      } )
     
    }
 

  return (
    <View className={styles.view} onClick={() => {
   
    }}>
      <View className={styles.container_one}>
        <Image
          src={!weathers.length ? "" : weathers[0].conditionNum === '120' ? qing : weathers[0].conditionNum === '142' ? duoyun : weathers[0].conditionNum === '129' ? shaoyun : weathers[0].conditionNum === '132' ? yintian : weathers[0].conditionNum === '139' ? xiaoyu : weathers[0].conditionNum === '101' ? dayu : weathers[0].conditionNum === '107' ? baoyu : weathers[0].conditionNum === '123' ? lzyu : weathers[0].conditionNum === '136' ? lzybybb : weathers[0].conditionNum === '137' ? dongyu : weathers[0].conditionNum === '113' ? yujiaxue : weathers[0].conditionNum === '105' ? xue : weathers[0].conditionNum === '124' ? daxue : weathers[0].conditionNum === '127' ? bingbao : weathers[0].conditionNum === '115' ? bingli : weathers[0].conditionNum === '133' ? bingzhen : weathers[0].conditionNum === '110' ? leidian : weathers[0].conditionNum === '102' ? leibao : weathers[0].conditionNum === '121' ? wu : weathers[0].conditionNum === '140' ? mai : weathers[0].conditionNum === '103' ? scb : weathers[0].conditionNum === '114' ? cjf : weathers[0].conditionNum === '117' ? yangsha : weathers[0].conditionNum === '109' ? fuc : shaoyun}
          className={styles.img_one}
        />
        <View className={styles.box_one}>
          <View className={styles.view_row}>
            <Text className={styles.font_one}>{Strings.getLang("today")}</Text>
            {hasWork(weathers.length ? weathers[0].sunRiseTimeStamp : '')}
          </View>

          <Text style={{ fontSize: "28rpx", fontWeight: "550" }}>{weathers.length ? weathers[0].tlow : ''}℃/{weathers.length ? weathers[0].thigh : ''}℃</Text>
        </View>
      </View>
      <View className={styles.container_two}>
        <Image
          src={!weathers.length ? "" : weathers[1].conditionNum === '120' ? qing : weathers[1].conditionNum === '142' ? duoyun : weathers[1].conditionNum === '129' ? shaoyun : weathers[1].conditionNum === '132' ? yintian : weathers[1].conditionNum === '139' ? xiaoyu : weathers[1].conditionNum === '101' ? dayu : weathers[1].conditionNum === '107' ? baoyu : weathers[1].conditionNum === '123' ? lzyu : weathers[1].conditionNum === '136' ? lzybybb : weathers[1].conditionNum === '137' ? dongyu : weathers[1].conditionNum === '113' ? yujiaxue : weathers[1].conditionNum === '105' ? xue : weathers[1].conditionNum === '124' ? daxue : weathers[1].conditionNum === '127' ? bingbao : weathers[1].conditionNum === '115' ? bingli : weathers[1].conditionNum === '133' ? bingzhen : weathers[1].conditionNum === '110' ? leidian : weathers[1].conditionNum === '102' ? leibao : weathers[1].conditionNum === '121' ? wu : weathers[1].conditionNum === '140' ? mai : weathers[1].conditionNum === '103' ? scb : weathers[1].conditionNum === '114' ? cjf : weathers[1].conditionNum === '117' ? yangsha : weathers[1].conditionNum === '109' ? fuc : shaoyun}
          className={styles.img_one}
        />
        <View className={styles.box_two}>
          <View className={styles.view_row}>   <Text className={styles.font_one}>{weathers.length ? getWeekdayFromTimestamp(weathers[1].sunRiseTimeStamp) : ''}</Text>
          {hasWork(weathers.length ? weathers[1].sunRiseTimeStamp : '')}
          </View>

          <Text style={{ fontSize: "28rpx", fontWeight: "550" }}>{weathers.length ? weathers[1].tlow : ''}℃/{weathers.length ? weathers[1].thigh : ''}℃</Text>

        </View>
      </View>
   
    </View>
  )
   
}
